# Maintainer: Felix Yan <felixonmars@archlinux.org>

pkgname=ruby-character_set
pkgver=1.6.0
_commit=6e397e267fbaf21858614a9bae250264739dd650
pkgrel=2
pkgdesc='Build, read, write and compare sets of Unicode codepoints'
arch=(loong64 x86_64)
url='https://github.com/jaynetics/character_set'
license=(MIT)
depends=(ruby-sorted_set)
makedepends=(git)
checkdepends=(ruby-benchmark-ips ruby-get_process_mem ruby-rake ruby-rake-compiler
              ruby-range_compressor ruby-regexp_parser ruby-regexp_property_values ruby-rspec
              ruby-rubocop)
options=(!emptydirs)
source=(git+https://github.com/jaynetics/character_set.git#commit=$_commit)
sha256sums=('SKIP')

prepare() {
  cd character_set
  sed -i -e 's|~>|>=|' character_set.gemspec
  sed -i -e '/codecov/d' -e '/gouteur/d' Gemfile
  # Don't recompile
  sed -i '/compile/d' Rakefile
  sed -i '/bundler/d' spec/spec_helper.rb
}

build() {
  local _gemdir="$(gem env gemdir)"
  cd character_set
  gem build character_set.gemspec
  gem install \
    --local \
    --verbose \
    --ignore-dependencies \
    --no-user-install \
    --install-dir "tmp_install/$_gemdir" \
    --bindir "tmp_install/usr/bin" \
    character_set-$pkgver.gem
  find "tmp_install/$_gemdir/gems/" \
    -type f \
    \( \
        -iname "*.o" -o \
        -iname "*.c" -o \
        -iname "*.so" -o \
        -iname "*.time" -o \
        -iname "gem.build_complete" -o \
        -iname "Makefile" \
    \) \
    -delete
  rm -r tmp_install/$_gemdir/cache
}

check() {
  local _gemdir="$(gem env gemdir)"
  cd character_set
  GEM_HOME="tmp_install/$_gemdir" rake
}

package() {
  cd character_set
  cp -a tmp_install/* "$pkgdir"/
  install -Dm644 LICENSE.txt -t "$pkgdir"/usr/share/licenses/$pkgname/
}
